Circle = class()

function Circle:init(x, y, size)
    ellipseMode(RADIUS)
    self.position = vec2(x, y)
    self.size = size
    self.isStroke = false
    self.strokeWidth = 3
    self.fillColor = color(0, 0, 0)
    self.isTouchedFillColor = color(0, 0, 0)
    self.strokeColor = color(0, 0, 0)
    self.isTouched = false
    self.touchedFunction = {function() end, "ENDED"}
end

function Circle:draw()
    if self.isStroke then
        strokeWidth(self.strokeWidth)
        stroke(self.strokeColor)
    else
        noStroke()
    end
    if not self.isTouched then
        fill(self.fillColor)
        ellipse(self.position.x, self.position.y, self.size)
    else
        fill(self.isTouchedFillColor)
        ellipse(self.position.x, self.position.y, self.size)
    end
end

function Circle:touched(touch) -- 如果需要，必须在touched中进行调用。
    if math.abs(self.position.x-touch.x) <= self.size and math.abs(self.position.y-touch.y) <= self.size and touch.state ~= ENDED then
        self.isTouched = true
    elseif math.abs(self.position.x-touch.x) <= self.size and math.abs(self.position.y-touch.y) <= self.size and touch.state == ENDED then
        self.isTouched = false
        if self.touchedFunction[2] == "ENDED" then
            self.touchedFunction[1]()
        end
    else
        self.isTouched = false
    end
end
